package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportUploadFiles;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportUploadFilesDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2020-06-14 12:47:47
 */
public class TransportUploadFilesConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportUploadFilesConverts.class);

    public static List<TransportUploadFilesDTO> convert(List<TransportUploadFiles> transportUploadFilesList) {
        if (CollectionUtils.isEmpty(transportUploadFilesList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportUploadFilesDTO> transportUploadFilesListResult = Lists.newArrayList();
        for (TransportUploadFiles transportUploadFiles : transportUploadFilesList) {
            transportUploadFilesListResult.add(convert(transportUploadFiles));
        }
        return transportUploadFilesListResult;
    }

    public static TransportUploadFilesDTO convert(TransportUploadFiles transportUploadFiles) {
        try {
            return BeanUtils.copy(transportUploadFiles, TransportUploadFilesDTO.class);
        } catch (Exception e) {
            LOG.error("TransportUploadFiles到TransportUploadFilesDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUploadFiles到TransportUploadFilesDTO转换失败", e);
        }
    }

    public static TransportUploadFiles convert(TransportUploadFilesDTO transportUploadFilesDTO) {
        try {
            return BeanUtils.copy(transportUploadFilesDTO, TransportUploadFiles.class);
        } catch (Exception e) {
            LOG.error("TransportUploadFilesDTO到TransportUploadFiles转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportUploadFilesDTO到TransportUploadFiles转换失败", e);
        }
    }
}